/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Interface.Patrocinador;

import static Interface.Global.aux;
import Modelo.Patrocinador.Patrocinador;
import Util.ExcecaoInstanciaNaoEncontrada;
import java.awt.Component;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author ana.siena
 */
public class AlterarPatrocinador extends javax.swing.JFrame {
    
    private String CNPJPatrocinador;
    private String novaRazaoSocialPatrocinador;
    private String novoNomeFantasiaPatrocinador;
    private String novoEndPatrocinador;
    private Patrocinador patro;

    /**
     * Creates new form AlterarPatrocinador
     */
    public AlterarPatrocinador() {
        initComponents();
        init();
    }
    
    private void init(){
	setVisible(true);
        setTitle("Alterar Patrocinador");
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        //Preenche combobox do evento
        /*ArrayList <Evento> vetorCNPJ = new ArrayList <Evento>();
        vetorCNPJ = (ArrayList<Evento>) aux.buscarTodosPatrocinadores();
        
        for(int i=0; i<vetorCodEvento.size();i++)
        {
            eventoCombo.addItem(vetorCodEvento.get(i).getCodEvento());
        }*/
    }
   

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        botaoConsultar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        CNPJtext = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        novaRazaoSocial = new javax.swing.JTextField();
        novoNomeFantasia = new javax.swing.JTextField();
        novoEnderecoPatrocinador = new javax.swing.JTextField();
        botaoRetornar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        razaoSocial1 = new javax.swing.JTextField();
        nomeFantasia1 = new javax.swing.JTextField();
        enderecoPatrocinador1 = new javax.swing.JTextField();
        botaoConsultar1 = new javax.swing.JButton();
        botaoAlterar = new javax.swing.JButton();

        botaoConsultar.setText("Consultar");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Patrocinador a ser alterado"));

        jLabel6.setText("CNPJ:");

        CNPJtext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CNPJtextActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addGap(68, 68, 68)
                .addComponent(CNPJtext, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(103, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(CNPJtext, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Alterações sobre o patrocinador"));

        jLabel3.setText("Razão Social:");

        jLabel4.setText("Nome Fantasia:");

        jLabel5.setText("Endereço:");

        novaRazaoSocial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novaRazaoSocialActionPerformed(evt);
            }
        });

        novoNomeFantasia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novoNomeFantasiaActionPerformed(evt);
            }
        });

        novoEnderecoPatrocinador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novoEnderecoPatrocinadorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(35, 35, 35)
                        .addComponent(novaRazaoSocial, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addGap(24, 24, 24)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(novoNomeFantasia)
                            .addComponent(novoEnderecoPatrocinador))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(novaRazaoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(novoNomeFantasia, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(novoEnderecoPatrocinador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        botaoRetornar.setText("Retornar");
        botaoRetornar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoRetornarActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setText("Alterar um Patrocinador");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados do patrocinador"));

        jLabel7.setText("Razão Social:");

        jLabel8.setText("Nome Fantasia:");

        jLabel9.setText("Endereço:");

        razaoSocial1.setEnabled(false);
        razaoSocial1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                razaoSocial1ActionPerformed(evt);
            }
        });

        nomeFantasia1.setEnabled(false);
        nomeFantasia1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nomeFantasia1ActionPerformed(evt);
            }
        });

        enderecoPatrocinador1.setEnabled(false);
        enderecoPatrocinador1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enderecoPatrocinador1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(35, 35, 35)
                        .addComponent(razaoSocial1))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addGap(24, 24, 24)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nomeFantasia1)
                            .addComponent(enderecoPatrocinador1))))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(razaoSocial1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(nomeFantasia1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(enderecoPatrocinador1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        botaoConsultar1.setText("Consultar");
        botaoConsultar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoConsultar1ActionPerformed(evt);
            }
        });

        botaoAlterar.setText("Alterar");
        botaoAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoAlterarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(113, 113, 113))
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(botaoRetornar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoConsultar1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoAlterar))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(28, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(botaoAlterar)
                        .addComponent(botaoConsultar1))
                    .addComponent(botaoRetornar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void novoNomeFantasiaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novoNomeFantasiaActionPerformed
        
    }//GEN-LAST:event_novoNomeFantasiaActionPerformed

    private void botaoRetornarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoRetornarActionPerformed
        new MenuPatrocinador().setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_botaoRetornarActionPerformed

    private void nomeFantasia1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nomeFantasia1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nomeFantasia1ActionPerformed

    private void botaoConsultar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoConsultar1ActionPerformed
    	       
        CNPJPatrocinador = CNPJtext.getText();
    	
    	try {
            patro = aux.buscaPatrocinador(CNPJPatrocinador);
        } catch (ExcecaoInstanciaNaoEncontrada ex) {
            Logger.getLogger(ConsultarPatrocinador.class.getName()).log(Level.SEVERE, null, ex);
            Component frame = null;
            JOptionPane.showMessageDialog(frame,ex.getMessage());
        }
        
        razaoSocial1.setText(patro.getRazaoSocialPatrocinador());
        nomeFantasia1.setText(patro.getNomeFantasiaPatrocinador());
        enderecoPatrocinador1.setText(patro.getEnderecoPatrocinador());
        
        this.novaRazaoSocial.setText(patro.getRazaoSocialPatrocinador());
        this.novoNomeFantasia.setText(patro.getNomeFantasiaPatrocinador());
        this.novoEnderecoPatrocinador.setText(patro.getEnderecoPatrocinador());
        
        
    }//GEN-LAST:event_botaoConsultar1ActionPerformed

    private void botaoAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoAlterarActionPerformed
        novoNomeFantasiaPatrocinador = novoNomeFantasia.getText();
        CNPJPatrocinador = CNPJtext.getText();
        novaRazaoSocialPatrocinador = novaRazaoSocial.getText();
        novoEndPatrocinador = novoEnderecoPatrocinador.getText();
        
        Patrocinador patrocinador = new Patrocinador(patro.getCnpjPatrocinador(),novaRazaoSocialPatrocinador,novoNomeFantasiaPatrocinador,novoEndPatrocinador);
        try {
            aux.updatePatrocinador(patrocinador);
        } catch (ExcecaoInstanciaNaoEncontrada ex) {
            Logger.getLogger(AlterarPatrocinador.class.getName()).log(Level.SEVERE, null, ex);
            Component frame = null;
            JOptionPane.showMessageDialog(frame,ex.getMessage());
        }
    }//GEN-LAST:event_botaoAlterarActionPerformed

    private void razaoSocial1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_razaoSocial1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_razaoSocial1ActionPerformed

    private void enderecoPatrocinador1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enderecoPatrocinador1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_enderecoPatrocinador1ActionPerformed

    private void novaRazaoSocialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novaRazaoSocialActionPerformed
        
    }//GEN-LAST:event_novaRazaoSocialActionPerformed

    private void novoEnderecoPatrocinadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novoEnderecoPatrocinadorActionPerformed
        
    }//GEN-LAST:event_novoEnderecoPatrocinadorActionPerformed

    private void CNPJtextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CNPJtextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_CNPJtextActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField CNPJtext;
    private javax.swing.JButton botaoAlterar;
    private javax.swing.JButton botaoConsultar;
    private javax.swing.JButton botaoConsultar1;
    private javax.swing.JButton botaoRetornar;
    private javax.swing.JTextField enderecoPatrocinador1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField nomeFantasia1;
    private javax.swing.JTextField novaRazaoSocial;
    private javax.swing.JTextField novoEnderecoPatrocinador;
    private javax.swing.JTextField novoNomeFantasia;
    private javax.swing.JTextField razaoSocial1;
    // End of variables declaration//GEN-END:variables
}
